package com.zjitc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zjitc.model.Category;
import com.zjitc.model.Evaluate;
import com.zjitc.model.Orders;
import com.zjitc.model.Product;
import com.zjitc.service.ProductService;
import java.util.List;
import javax.lang.model.element.NestingKind;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import sun.management.snmp.AdaptorBootstrap.DefaultValues;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/25 16:13
 * @description:
 */
@Controller
public class ProductController {



  @Autowired
  private ProductService productService;

  @RequestMapping("/findByCid")
  public String findByCid(HttpSession session, Integer cid,
      @RequestParam(name = "start", required = false, defaultValue = "1") int start,
      @RequestParam(name = "count", required = false, defaultValue = "12") int count) {
    List<Category> list = productService.findAllCategory();
    List<Product> products = productService.findPageByCid(cid);
    PageHelper.startPage(start,count);
    PageInfo<Product> pageInfo = new PageInfo(products);
    session.setAttribute("cid", cid);
    session.setAttribute("clist", list);
    session.setAttribute("page", pageInfo);
    return "/WEB-INF/user/productList.jsp";
  }


  @RequestMapping("/findByPid")
  public String findByPid(HttpSession session, int pid) {
    Product product = productService.findProductById(pid);
    session.setAttribute("product", product);
    return "/WEB-INF/user/product.jsp";
  }

  @RequestMapping("/findByCsid")
  public String findByCsid(HttpSession session, int csid,
      @RequestParam(name = "start", required = false, defaultValue = "1") int start,
      @RequestParam(name = "count", required = false, defaultValue = "12") int count) {
    List<Product> product = productService.findPageByCsid(csid);
    PageHelper.startPage(start,count);
    PageInfo<Product> pageInfo=new PageInfo<>(product);
    session.setAttribute("csid", csid);
    session.setAttribute("cspage", pageInfo);
    return "/WEB-INF/user/product_secondList.jsp";

  }

}
